package org.itworks.biodev.gui;

import java.util.*;

import org.itworks.biodev.model.*;
import org.itworks.helpers.*;

public class EditProductDialogModel extends Observable {

	private Vector<ProductSubCategory> productSubCategories;
	private Vector<Unit> units;
	private Vector<VATRate> vatRates;
	private Vector<ProductTypeSpecificity> productTypeSpecificities;
	private boolean isUpdating = false;
	private Vector<ProductTypeSpecificity> selectedProductSpecificities;
	private Product product;
	
	public EditProductDialogModel() {
		selectedProductSpecificities = new Vector<ProductTypeSpecificity>();
	}
	
	public Vector<ProductSubCategory> getProductSubCategories() {
		return this.productSubCategories;
	}
	
	public Vector<Unit> getUnits() {
		return this.units;
	}
	
	public Vector<VATRate> getVatRates() {
		return this.vatRates;
	}
	
	public void setProductSubCategories(Vector<ProductSubCategory> productSubCategories) {
		this.productSubCategories = productSubCategories;
		
		this.setChanged();
		this.notifyObservers(
			new MVCNotification(EditProductDialogView.FILL_COMBOBOX_PRODUCTSUBCATEGORIES, this.productSubCategories)
		);
		this.clearChanged();
	}
	
	public void setUnits(Vector<Unit> units) {
		this.units = units;
		
		this.setChanged();
		this.notifyObservers(
			new MVCNotification(EditProductDialogView.FILL_COMBOBOX_UNITS, this.units)
		);
		this.clearChanged();
		
	}
	
	public void setVatRates(Vector<VATRate> vatRates) {
		this.vatRates = vatRates;
		
		this.setChanged();
		this.notifyObservers(
			new MVCNotification(EditProductDialogView.FILL_COMBOBOX_VATRATES, this.vatRates)
		);
		this.clearChanged();
	}
	
	public boolean getisUpdating() {
		return this.isUpdating;
	}
	
	public void setIsUpdating(boolean isUpdating) {
		this.isUpdating = isUpdating; 
	}
	
	public Vector<ProductTypeSpecificity> getProductTypeSpecificities() {
		return productTypeSpecificities;
	}

	public void setProductSpecificities(
			Vector<ProductTypeSpecificity> productTypeSpecificities) {
		// TODO Auto-generated method stub
		this.productTypeSpecificities = productTypeSpecificities;
		
		this.setChanged();
		this.notifyObservers(new MVCNotification(EditProductDialogView.FILL_SPECIFICITIES_COMBOBOX, productTypeSpecificities));
		this.clearChanged();
		
	}

	public Vector<ProductTypeSpecificity> getSelectedProductSpecificities() {
		return selectedProductSpecificities;
	}

	public void setSelectedProductSpecificities(
			Vector<ProductTypeSpecificity> selectedProductSpecificities) {
		this.selectedProductSpecificities = selectedProductSpecificities;
		
		this.setChanged();
		this.notifyObservers(new MVCNotification(EditProductDialogView.FILL_SPECIFICITIES_LIST, selectedProductSpecificities));
		this.clearChanged();
	}
	
	public void addSelectedProductSpecificity(ProductTypeSpecificity productTypeSpecificity) {
		
		selectedProductSpecificities.add(productTypeSpecificity);
		
		this.setChanged();
		this.notifyObservers(new MVCNotification(EditProductDialogView.ADD_SPECIFICITY_TO_LIST, productTypeSpecificity));
		this.clearChanged();
	}

	public Product getProduct() {
		return product;
	}

	public void setProduct(Product product) {
		this.product = product;
	}
	
	public void setInitProduct(Product product) {
		this.product = product;
		
		// Notifier
	}
}
